# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

file(GLOB bzip_source patch/*.c)
include_directories(${CMAKE_SOURCE_DIR}/patch/inc)

# add_library()命令用于向CMake添加依赖源文件或库
# 指令需传入三个参数（函数库名称、库类型、依赖源文件相对路径）
add_library( # 生成函数库的名称，即libnative-lib.so或libnative-lib.a(lib和.so/.a默认缺省)
        native-lib

        # 生成库类型：动态库为SHARED，静态库为STATIC
        SHARED

        # 依赖的c/cpp文件(相对路径)
        native-lib.cpp
        file-option-lib.c
        ffmpeg-test.c
        ffmpeg-player.c
        ffmpeg_voicer.c
        audio_player.c
        effects_qq_voicer.cpp
        ${bzip_source}
        bzip.c)


# find_library()命令用于定位NDK中的库
# 需传入两个参数(path变量、ndk库名称)
find_library( # 设置path变量的名称，这里为NDK中的日志库
        log-lib

        #指定cmake查询库的名称
        #即在ndk开发包中查询liblog.so函数库，将其路径赋值给log-lib
        log)

#设置第三方库头文件所在位置
include_directories(${CMAKE_SOURCE_DIR}/ffmpeg_include)

#设置so库
set(third_lib_path ${CMAKE_SOURCE_DIR}/../../../libs)

add_library( libavcodec-56
        SHARED
        IMPORTED )
set_target_properties( libavcodec-56
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libavcodec-56.so )

add_library( libavdevice-56
        SHARED
        IMPORTED )
set_target_properties( libavdevice-56
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libavdevice-56.so )

add_library( libavfilter-5
        SHARED
        IMPORTED )
set_target_properties( libavfilter-5
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libavfilter-5.so )

add_library( libavformat-56
        SHARED
        IMPORTED )
set_target_properties( libavformat-56
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libavformat-56.so )

add_library( libavutil-54
        SHARED
        IMPORTED )
set_target_properties( libavutil-54
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libavutil-54.so )

add_library( libpostproc-53
        SHARED
        IMPORTED )
set_target_properties( libpostproc-53
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libpostproc-53.so )

add_library( libswresample-1
        SHARED
        IMPORTED )
set_target_properties( libswresample-1
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libswresample-1.so )

add_library( libswscale-3
        SHARED
        IMPORTED )
set_target_properties( libswscale-3
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libswscale-3.so )

#设置第三方库头文件所在位置
include_directories(${CMAKE_SOURCE_DIR}/fmod_include)

add_library( libfmod
        SHARED
        IMPORTED )
set_target_properties( libfmod
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libfmod.so )

add_library( libfmodL
        SHARED
        IMPORTED )
set_target_properties( libfmodL
        PROPERTIES IMPORTED_LOCATION
        ${third_lib_path}/armeabi-v7a/libfmodL.so )


#target_link_libraries()命令用于指定要关联到的原生库的库
target_link_libraries( # 指定目标库，与上面指定的函数库名一致
        native-lib

        #ffmpeg
        libavcodec-56
        libavdevice-56
        libavfilter-5
        libavformat-56
        libavutil-54
        libpostproc-53
        libswresample-1
        libswscale-3

        #fmod
        libfmod
        libfmodL

        -landroid # 添加移植的android NDK库

        # 链接的库，根据log-lib变量对应liblog.so函数库
        ${log-lib})

